const path=require('path')
var name = path.basename(__filename, '.js')//本文件名

var resolve = (recvStr) => {
    var arr = recvStr.split(',')
    var result = {}
    if (!arr | arr.length != 9) {
        console.log(arr.length)
        result.status = false
        result.msg = '数据长度错误'
    } else {
        result.status = true
        result.msg = 'ok'
        result.data = {}
        result.data.type=arr[0].trim()
        result.data.longDiameter =arr[1]
        result.data.longDiameterLevel=arr[2].trim()
        result.data.shortDiameter=arr[3]
        result.data.shortDiameterLevel=arr[4].trim()
        result.data.topRS=arr[5]
        result.data.topRSLevel=arr[6].trim()
        result.data.bottomRS=arr[7]
        result.data.bottomRSLevel=arr[8].trim()
        result.data.timeStamp=Date.now()
    }
    return result
}

var parserRule = (port) => {
    var Readline = require('@serialport/parser-readline')
    var ByteLength = require('@serialport/parser-byte-length')//指定数据帧字节长度，略
    var parser = port.pipe(new Readline({ delimiter: '\r\n' }))//以回车换行为结束标记
    return parser
}

module.exports = {
    name,
    parserRule,
    resolve
}